<?php

/**
 * sfGuardUser form.
 *
 * @package    appcemhti
 * @subpackage form
 * @author     Steve Cancès
 * @version    SVN: $Id: sfDoctrinePluginFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class sfGuardUserForm extends PluginsfGuardUserForm
{
    public function configure()
    {
        unset(
                $this['created_at'],
                $this['last_login'],
                $this['is_active'],
                $this['is_super_admin'],
                $this['algorithm'],
                $this['salt']
        );
        
        //$this->setWidget('username', new sfWidgetFormInputHidden());
        $this->widgetSchema['username'] = new sfWidgetFormInputPassword();
        $this->widgetSchema['updated_at'] = new sfWidgetFormInputPassword();
        $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
        $this->widgetSchema['password']->setAttribute("qtip", "A laiser vide pour ne pas modifier le mot de passe");
        $this->widgetSchema['password_bis'] = new sfWidgetFormInputPassword();
        $this->widgetSchema['email_address']->setAttribute("autocomplete", "off");
        $this->widgetSchema['email_address']->setAttribute("qtip", "L'adresse email doit être valide");
        
        $this->validatorSchema['password']     = new sfValidatorString(array('required' => false), array('min_length' => '"%value%" est trop court (%min_length% lettres minimum).'));
        $this->validatorSchema['password_bis'] = new sfValidatorString(array('required' => false), array('min_length' => '"%value%" est trop court (%min_length% lettres minimum).'));
        $this->validatorSchema['email_address'] = new sfValidatorEmail(array('required' => true, 'max_length' => 255), array('invalid' => 'Cet email n\'est pas valide.', 'required' => 'Champ obligatoire.'));
        $this->validatorSchema['username'] = new sfValidatorString(array('required' => false, 'max_length' => 128));
        
        $this->mergePostValidator(new sfValidatorSchemaCompare(
            'password',
            sfValidatorSchemaCompare::EQUAL,
            'password_bis',
            array(),
            array('invalid' => 'Les champs doivent être identiques.')
        ));
        
        $this->getValidator('first_name')->setMessage('max_length', '"%value%" est trop long (%max_length% lettres maximum).');
        $this->getValidator('last_name')->setMessage('max_length', '"%value%" est trop long (%max_length% lettres maximum).');
    }
}
